package com.atguigu.gmall.weball.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.cart.CartFeign;
import com.atguigu.gmall.model.cart.CartItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/9/9 16:23
 */
@Controller
public class CartController {
    @Autowired
    CartFeign cartFeign;
    @GetMapping("/cart.html")
    public String cart(){

        return "cart/index";
    }
    //addCart.html?skuId=42&skuNum=1&sourceType=query
    @GetMapping("/addCart.html")
    public String addCart(@RequestParam("skuId")Long skuId,
                          @RequestParam("skuNum")Integer skuNum,
                          Model model){
        Result<CartItem> cartItemResult = cartFeign.addCart(skuId, skuNum);
        if (cartItemResult.isOk()){
            model.addAttribute("skuInfo",cartItemResult.getData());
            model.addAttribute("skuNum",cartItemResult.getData().getSkuNum());
        }

        return "cart/addCart";
    }

    @GetMapping("/cart/deleteChecked")
    public String deleteChecked(){
        cartFeign.deleteChecked();
        return "cart/index";
    }
    @GetMapping("/cart/collectChecked")
    public String CollectChecked(){
        return "cart/collect";
    }
}
